Skip to content

Conversation

@jacob-keller
Copy link

When tracking the bat positions it is possible for the different lines
to arrive in an arbitrary order. This results in the callout being
inconsistent even when the bats are in the same position. For example it
might call out "away from bats S/N" instead of always consistently
saying "away from bats N/S".

Use sort() to make sure the bat callouts are consistent and always
display the directions in the same order.

When tracking the bat positions it is possible for the different lines
to arrive in an arbitrary order. This results in the callout being
inconsistent even when the bats are in the same position. For example it
might call out "away from bats S/N" instead of always consistently
saying "away from bats N/S".

Use sort() to make sure the bat callouts are consistent and always
display the directions in the same order.
@github-actions github-actions bot added raidboss /ui/raidboss module needs-review Awaiting review labels Feb 2, 2026
@jacob-keller
Copy link
Author

It bothered me that the callouts for blast beat would sometimes have the order different. It helps with readability if the order is consistent, and I think the sort for the DirectionOutput16 type will prioritize ordering them based in the north to south output. This will make it easier to parse the output and ensure that the bat position for your relative spot is easier to find quickly. (Rather than having to search for it in a set of 2 or 3 outcomes that might be in arbitrary order).

@xiashtra
Copy link
Collaborator

xiashtra commented Feb 2, 2026

I believe this will give unexpected output with the default sort function. For example, if the results were N, NNE, and ENE, the default sort function will return ENE, N, NNE, since the default sort is lexicographical order. I expect what you want is for the positions to return in N -> clockwise order, which would require a custom sort function.

@valarnin
Copy link
Collaborator

valarnin commented Feb 2, 2026

Something like this should give a consistent sort order, but might need to swap l/r:

        const [dir1, dir2] = data.bats.inner.sort((l, r) => Directions.output16Dir.indexOf(l) - Directions.output16Dir.indexOf(r));

@xiashtra
Copy link
Collaborator

xiashtra commented Feb 2, 2026

Something like this should give a consistent sort order, but might need to swap l/r:

        const [dir1, dir2] = data.bats.inner.sort((l, r) => Directions.output16Dir.indexOf(l) - Directions.output16Dir.indexOf(r));

An alternative would be to sort the numerical results from hdgTo16DirNum before converting them to output16Dir strings, but that would require more extensive changes.

@jacob-keller
Copy link
Author

I'll likely implement common sort function in the util.ts for each of the directions based on their index and use that. Should have it updated tonight

Add a custom sorting function for direction outputs which sorts
directions based on the index in the output16Dir. This works because
DirectionOutput16 is a superset of all the directions and is listed in
clockwise order starting with 'dirN'. By implementing a single function
we don't need to implement a separate custom function per each direction
type, and we don't need to re-implement the sorting logic at each code
point where sorting is required.
@github-actions github-actions bot added the resources /resources label Feb 3, 2026
@jacob-keller
Copy link
Author

I added a compareDirectionOutput function which can take any DirectionOutput* variable and compares it using the index into the output16Dir, which I think is sufficient and avoids needing to duplicate this logic all over.

@github-actions github-actions bot removed the needs-review Awaiting review label Feb 3, 2026
Co-authored-by: valarnin <valarnin@gmail.com>
@github-actions github-actions bot added the needs-review Awaiting review label Feb 3, 2026
The indexOf returns -1 rather than undefined if the value is not in the
array. This causes 'unknown' to sort to the front instead of to the back
of the array.

Fix this by using a lambda expression for getting the index, which
checks for the case where index is less than 0, and returns the array
length instead (which is after all indexes in the array).

Also simplify the function by returning the difference between the
indices instead of using multiple compares. This works because the
compare function just needs to return negative if a is first, positive
if a is second, and 0 if they have the same sort value. This is simpler
than multiple separate comparisons since we know our indexes are
numbers.
@jacob-keller jacob-keller requested a review from valarnin February 4, 2026 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-review Awaiting review raidboss /ui/raidboss module resources /resources

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants